
import std.string:toStringz;

import derelict.devil.il;
import derelict.sdl.sdl;//tmp

class Image{
	uint	w, h, bpp;
	ubyte*	data;


	this(char[] path){
		ilEnable(IL_ORIGIN_SET);
		ilOriginFunc(IL_ORIGIN_UPPER_LEFT);

		ILuint ilId;
		{
			ilGenImages(1, &ilId);
			ilBindImage(ilId);
			ilLoad(IL_TYPE_UNKNOWN, toStringz(path));
		}

		w	= ilGetInteger(IL_IMAGE_WIDTH);
		h	= ilGetInteger(IL_IMAGE_HEIGHT);
		bpp	= ilGetInteger(IL_IMAGE_BITS_PER_PIXEL);
	
		assert(bpp == 24);
		data = cast(ubyte*)ilGetData();
	}

	uint getPixel(uint x, uint y){
		assert(bpp==24);
		ubyte *p = data + y*3 * w + x * 3;//Uint8->ubyte
		return cast(uint)(*p *256*256 + *(p+1) *256 + *(p+2));
	}


}
